//-----------------------------------------------------------------------------
#include <QtDebug>
#include <QStringList>
#include <cmath>
#include "CMyDouble.h"
//-----------------------------------------------------------------------------
CMyDouble::CMyDouble(void) {
    entier = 0;
    decimaux = 0;
    null = true;
    signe = 1;
	inBeginDecimaux = false;
}
//-----------------------------------------------------------------------------
CMyDouble::CMyDouble(const CMyDouble& other) {
    entier = other.entier;
    decimaux = other.decimaux;
    null = other.null;
    signe = other.signe;
}
//-----------------------------------------------------------------------------'
CMyDouble::CMyDouble(double value) {
    CMyDouble(fromDouble(value));
}
//-----------------------------------------------------------------------------
CMyDouble CMyDouble::fromDouble(double value) {
    CMyDouble myDouble;
    QString s;

    myDouble.null = false;

    if(value < 0) {
        myDouble.signe = -1;
    }

    s=QString::number(std::abs(value), 'f', 6);
    sscanf(s.toAscii().data(), "%lu.%lu", &myDouble.entier, &myDouble.decimaux);

    return myDouble;
}
//-----------------------------------------------------------------------------
double CMyDouble::toDouble(void) const {
    return toString().toDouble();
}
//-----------------------------------------------------------------------------
bool CMyDouble::hasDecimaux(void) const {
    return (decimaux != 0 || inBeginDecimaux);
}
//-----------------------------------------------------------------------------
bool CMyDouble::isNull(void) const {
    return null;
}
//-----------------------------------------------------------------------------
QString CMyDouble::toString(void) const {
    QString s = "0";

    if(!null) {
        s = "";
        if(signe == -1) {
            s = "-";
        }
        s += QString::number(entier);
		
		if(hasDecimaux()) {
			s +=+"."+QString::number(decimaux);
		}
    }

    return s;
}
//-----------------------------------------------------------------------------
CMyDouble& CMyDouble::operator=(CMyDouble other) {
	entier = other.entier;
	decimaux = other.decimaux;
	signe = other.signe;
	null = other.null;

    return *this;
}
//-----------------------------------------------------------------------------
